package com.cold.demo.template.exh;

import com.cold.demo.template.pojo.Res;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@RestControllerAdvice
public class CommonExceptionHandler {


    private final Logger log = LoggerFactory.getLogger(CommonExceptionHandler.class);


    @ExceptionHandler(value = {NullPointerException.class})
    public Object handlerNullPointerException(NullPointerException e) {
        log.error("...NullPointerException：", e);
        e.printStackTrace();
        return Res.error("NULL POINTER ERROR");
    }


    @ExceptionHandler(value = {IOException.class})
    public Object handlerIOException(IOException e) {
        log.error("...IOException：", e);
        e.printStackTrace();
        return Res.error("IO ERROR");
    }


    @ExceptionHandler(value = {Exception.class})
    public Object handlerException(Exception e) {
        log.error("...Exception：", e);
        e.printStackTrace();
        return Res.error("ERROR");
    }
}
